﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

/*
 * TH07 Groep 10
 * ----------------------------------------------------------------------------------
 * Versie   Door        Commentaar
 * 0.1      Luca        Opzet en getDeformtionType op pixel threshold
 *
 * 
 */

namespace Algorithms_10.Deformation
{
    /// <summary>
    /// Checked het type van de vervorming
    /// </summary>
    public static class DeformationCheck
    {
        private static Point tL, tR, bL, bR;
        /// <summary>
        /// Enum, met de verschillende soorten deformaties.
        /// </summary>
        public enum DeformationEnum
        {
            SmallRight, SmallLeft, SmallTop, SmallBottom,
            TopLeftToBottomRight, TopRightToBottomLeft, BottomLeftToTopRight, BottomRightToTopLeft,
            noDeformation
        }

        /// <summary>
        /// Verkrijg het type deformatie, of de conclusie dat er geen deformatie is
        /// </summary>
        /// <param name="topLeft">Point met coordinaten van boven linker hoek</param>
        /// <param name="topRight">Point met coordinaten van boven rechter hoek</param>
        /// <param name="bottomLeft">Point met coordinaten van de onder linker hoek</param>
        /// <param name="bottomRight">Point met coordinaten van de rechter onderhoek</param>
        /// <param name="threshold">de threshold in pixels</param>
        public static DeformationEnum getDeformationType(Point topLeft, Point topRight, Point bottomLeft, Point bottomRight, int threshold)
        {

            tL = topLeft;
            tR = topRight;
            bL = bottomLeft;
            bR = bottomRight;


            // SmallRight
            if (tR.Y > tL.Y + threshold)
            {
                // if (bL.Y > bR.Y + threshold) return DeformationEnum.SmallRight;
                // overbodig, voor het repareren van een smallRight 
                // maakt het niet uit of de onderste lijn recht of schuin is 
                if (bR.Y > bL.Y + threshold)
                    return DeformationEnum.TopLeftToBottomRight;
                else return DeformationEnum.SmallRight;
            }
            else if (bR.Y > bL.Y + threshold)
            {
                if (tR.Y > tL.Y + threshold)
                    return DeformationEnum.TopLeftToBottomRight;
                else return DeformationEnum.SmallRight;
            }

            // SmallLeft
            if (tL.Y > tR.Y + threshold)
            {
                if (bL.Y > bR.Y + threshold)
                    return DeformationEnum.TopRightToBottomLeft;
                else return DeformationEnum.SmallLeft;
            }
            else if (bL.Y > bR.Y + threshold)
            {
                if (tL.Y > tR.Y + threshold)
                    return DeformationEnum.TopRightToBottomLeft;
                else return DeformationEnum.SmallLeft;
            }

            //smalltop
            if (tL.X > bL.X + threshold)
            {
                if (tR.X > bR.X + threshold)
                    return DeformationEnum.BottomLeftToTopRight;
                else return DeformationEnum.SmallTop;

            }
            else if (bR.X > tR.X + threshold)
            {
                if (bL.X > tL.X + threshold)
                    return DeformationEnum.BottomLeftToTopRight;
                else return DeformationEnum.SmallTop;
            }

            //SmallBottom
            if (bL.X > tL.X + threshold)
            {
                if (bR.X > tL.X + threshold)
                    return DeformationEnum.BottomRightToTopLeft;
                else return DeformationEnum.SmallBottom;
            }
            else if (bR.X > tL.X + threshold)
            {
                if (bL.X > tL.X + threshold)
                    return DeformationEnum.BottomRightToTopLeft;
                else return DeformationEnum.SmallBottom;

            }

            //niks gevonden dus geen deformatie.
            return DeformationEnum.noDeformation;

        }
    }
}
